<template>
  <div>
    <div id="breadcrumb">
      <a-breadcrumb>
        <a-breadcrumb-item>角色列表</a-breadcrumb-item>
      </a-breadcrumb>
    </div>
    <a-card :bordered="false">
      <div id="btn">
        <router-link to="/admin/role/edit/0">
          <a-button icon="plus">新 增</a-button>
        </router-link>
      </div>
      <a-table
          size="middle"
          rowKey="id"
          :columns="columns"
          :data-source="adminRoleList"
          :pagination="false"
      >
        <template slot="action" slot-scope="text, record">
          <router-link :to="`/admin/role/edit/${record.id}`">编辑</router-link>
        </template>
      </a-table>
    </a-card>
  </div>
</template>

<script>
export default {
  name: "AdminRole",

  data() {
    return {
      columns: [
        {
          title: 'ID',
          dataIndex: 'id'
        },
        {
          title: '角色名称',
          dataIndex: 'name'
        },
        {
          title: '创建时间',
          dataIndex: 'created_at'
        },
        {
          title: '更新时间',
          dataIndex: 'updated_at'
        },
        {
          title: '操作',
          dataIndex: 'action',
          scopedSlots: {customRender: 'action'},
        }
      ],
      adminRoleList: [],
    }
  },

  mounted() {
    this.getAdminRole()
  },

  methods: {
    getAdminRole() {
      this.$http.get('api/admin/role').then((result) => {
        this.adminRoleList = result
      }, (error) => {
        this.$message.error(error.message)
      })
    },
  }
}
</script>

<style scoped>
#breadcrumb {
  margin-top: 0;
  margin-bottom: 10px;
}

#btn {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 10px;
}
</style>